package com.neusoft.neuiotms.dcam.fixed.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.neuiotms.dcam.fixed.dto.AssetCodeRuleDTO;
import com.neusoft.neuiotms.dcam.fixed.service.AssetCodeRuleService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "资产编码规则")
@RestController
@RequestMapping(value = "/api/w/assetCodeRule")
public class AssetCodeRuleController {
	
	@Autowired
	private AssetCodeRuleService assetCodeRuleService;

	@ApiOperation("查询所有资产编码规则")
    @GetMapping
    public ResultListDTO<AssetCodeRuleDTO> index() {
        final List<AssetCodeRuleDTO> assetCodeRuleDTOs = this.assetCodeRuleService.findAll();
        return ResultListDTO.success(assetCodeRuleDTOs);
    }

    @ApiOperation("创建资产编码规则")
    @PostMapping
    public ResultDTO<AssetCodeRuleDTO> create(@RequestBody final AssetCodeRuleDTO dto) {
        final AssetCodeRuleDTO result = this.assetCodeRuleService.create(dto);
        return ResultDTO.success(result);
    }

    @ApiOperation("资产编码规则详情")
    @GetMapping("/{id}")
    public ResultDTO<AssetCodeRuleDTO> details(@PathVariable final Long id) {
        final AssetCodeRuleDTO dto = this.assetCodeRuleService.details(id);
        return ResultDTO.success(dto);
    }

    @ApiOperation("删除资产编码规则")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.assetCodeRuleService.delete(id);
        return ResultDTO.success();
    }

    @ApiOperation("修改资产编码规则")
    @PutMapping("/{id}")
    public ResultDTO<AssetCodeRuleDTO> update(@PathVariable final Long id,
            @RequestBody final AssetCodeRuleDTO dto) {
        final AssetCodeRuleDTO result = this.assetCodeRuleService.update(id, dto);
        return ResultDTO.success(result);
    }
    
}
